// miniprogram/pages/writeInPage/writeInPage.js
var _contentNavigationService = require("../../services/contentNavigationService.js");

var _moodStorage = require("../../services/MoodStorage.js");
var _timeStamp = require("../../services/timeStamp.js");

var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    moodId: 0,
    moodItem: {},
    year: new Date().getFullYear(),      // 年份
    month: new Date().getMonth() + 1,    // 月份
    day: new Date().getDate(),
    text:"",//文本
  },
 
  result_button_bindtap: function (event) {
    var that=this;
    _moodStorage.addMoodRecordAsync({
       TimeStamp:Date.parse(new Date()),//时间戳
       Weak:new Date().getDay(),
       month:_timeStamp.timeStampToDate(Date.parse(new Date()),'M'),
       Weather:app.globalData.todayWeather,
       Mood:this.data.moodId,
       MoodDegree:0,
       Diary:event.detail.value.text,
    },function(){
      _contentNavigationService.navigateToAsync(
        _contentNavigationService.resultPage,that.data
      )
    },function(){
      wx.showToast({
        title: '记录失败',
        icon:'none',
      })
    }
    )
    that.setData({
      text: event.detail.value.text,
      weather: app.globalData.todayWeather
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (event) {
    var id = _contentNavigationService.getParameter(_contentNavigationService.writeInPage)
    this.setData({
      moodId: id,
      moodItem: app.globalData.moodList[id],
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})